extends layout

block headContent
	title RPC Terminal

block content
	div(class="row")
		div(class="col")
			h1(class="h3") RPC Terminal

		div(class="col")
			if (!config.demoSite && (!config.credentials.rpc || !config.credentials.rpc.rpc))
				span(style="float: right;")
					a(href="/disconnect", class="btn btn-secondary") Disconnect from node
	
	hr

	:markdown-it
		Use this interactive terminal to send RPC commands to your node. Results will be shown inline. To browse all available RPC commands you can use the [RPC Browser](/rpc-browser).

	div(class="card mb-3")
		div(class="card-body")
			form(id="terminal-form")
				div(class="form-group")
					label(for="input-cmd") Command
					input(type="text", id="input-cmd", name="cmd", class="form-control")

				input(type="submit", class="btn btn-primary btn-block", value="Send")

	hr
	
	div(id="terminal-output")

block endOfBody
	script.
		$(document).ready(function() {
			$("#terminal-form").submit(function(e) {
				e.preventDefault();

				var cmd = $("#input-cmd").val()

				var postData = {};
				postData.cmd = cmd;
				
				$.post(
					"/rpc-terminal",
					postData,
					function(response, textStatus, jqXHR) {
						var t = new Date().getTime();

						$("#terminal-output").prepend("<div id='output-" + t + "' class='card mb-3'><div class='card-body'><h5>" + cmd + "</h5><pre><code>" + response + "</code></pre></div></div>");
						console.log(response);

						$("#output-" + t + " pre code").each(function(i, block) {
							hljs.highlightBlock(block);
						});
						
						return false;
					})
					.done(function(data) {
					});

				return false;
			});
		});